home *** CD-ROM | disk | FTP | other *** search
- /*
- CopyRoms.c
-
- Copyright (C) 2005 Paul Pratt
-
- You can redistribute this file and/or modify it under the terms
- of version 2 of the GNU General Public License as published by
- the Free Software Foundation. You should have received a copy
- of the license along with this file; see the file COPYING.
-
- This file is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- license for more details.
- */
-
- /*
- Much of the information about ROM checksums was found at:
- "http://mes.emuunlim.com/tips/rom_checksums.htm"
- "http://homepage3.nifty.com/toshi3/list.html"
- "http://www.yama-arashi.com/com-mac/"
- "http://www.geocities.com/va_macs4me/"
- "http://dragonstar-realm.net/MacFaq/Roms.html"
- */
-
- #include <types.h>
- #include <limits.h>
- #include <stddef.h>
- #include <SegLoad.h>
- #include <Script.h>
- #include <Files.h>
- #include <Devices.h>
- #include <Windows.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
-
- #define ROMBase 0x02AE
-
- #define MyCreator 'MnvM'
- #define MyFileType 'ROM!'
-
- QDGlobals qd;
-
- /*
- Don't have 'main', and instead have a bit of assembly
- language call 'MyStart', to avoid the glue code of
- a development environment that doesn't really support
- Macintosh 128K
- */
-
- void MyStart(void);
-
- void MyStart(void)
- {
- OSErr err;
- unsigned long Length;
- StringPtr MyFileName;
- short VRefNum;
- Ptr StartAddr;
- unsigned long CheckSum;
-
- ParamBlockRec b;
-
- InitGraf((Ptr)&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
-
- StartAddr = *(Ptr *)ROMBase;
- CheckSum = *(unsigned long *)StartAddr;
-
- /*
- Guess what ROM this is from its checksum.
- */
-
- if ((CheckSum == 0x28BA61CE)
- || (CheckSum == 0x28BA4E50))
- {
- Length = (64 * 1024UL);
- MyFileName = ((StringPtr)"\pMac128K.ROM");
- } else
- if ((CheckSum == 0x4D1EEEE1)
- || (CheckSum == 0x4D1EEAE1)
- || (CheckSum == 0x4D1F8172))
- {
- Length = (128 * 1024UL);
- MyFileName = ((StringPtr)"\pvMac.ROM");
- } else
- if (CheckSum == 0xB2E362A8)
- {
- Length = (256 * 1024UL);
- MyFileName = ((StringPtr)"\pMacSE.ROM");
- } else
- if ((CheckSum == 0x9779D2C4)
- || (CheckSum == 0x97851DB6))
- {
- Length = (256 * 1024UL);
- MyFileName = ((StringPtr)"\pMacII.ROM");
- } else
- if (CheckSum == 0x97221136)
- {
- Length = (256 * 1024UL);
- MyFileName = ((StringPtr)"\pMacIIx.ROM");
- } else
- if (CheckSum == 0xB306E171)
- {
- Length = (256 * 1024UL);
- MyFileName = ((StringPtr)"\pSEHDFD.ROM");
- } else
- if (CheckSum == 0x96645F9C) {
- Length = (256 * 1024UL);
- MyFileName = ((StringPtr)"\pPB100.ROM");
- } else
- if (CheckSum == 0x368CADFE) {
- Length = (512 * 1024UL);
- MyFileName = ((StringPtr)"\pMacIIci.ROM");
- } else
- if ((CheckSum == 0x4147DD77)
- || (CheckSum == 0x35C28C8F))
- {
- Length = (512 * 1024UL);
- MyFileName = ((StringPtr)"\pMacIIfx.ROM");
- } else
- if (CheckSum == 0x36B7FB6C) {
- Length = (512 * 1024UL);
- MyFileName = ((StringPtr)"\pMacIIsi.ROM");
- } else
- if (CheckSum == 0xA49F9914) {
- Length = (512 * 1024UL);
- MyFileName = ((StringPtr)"\pClassic.ROM");
- } else
- if (CheckSum == 0x350EACF0) {
- Length = (512 * 1024UL);
- MyFileName = ((StringPtr)"\pMacLC.ROM");
- } else
- if (CheckSum == 0x3193670E) {
- Length = (512 * 1024UL);
- MyFileName = ((StringPtr)"\pClassicII.ROM");
- } else
- if (CheckSum == 0x420DBFF3) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pQuad900.ROM");
- } else
- if (CheckSum == 0x35C28F5F) {
- Length = (512 * 1024UL);
- MyFileName = ((StringPtr)"\pMacLCII.ROM");
- } else
- if (CheckSum == 0x3DC27823) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pQuad950.ROM");
- } else
- if (CheckSum == 0x49579803) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pMacIIvx.ROM");
- } else
- if (CheckSum == 0xE33B2724) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pPB165.ROM");
- } else
- if ((CheckSum == 0xECFA989B)
- || (CheckSum == 0xECFA89A8))
- {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pDuo230.ROM");
- } else
- if (CheckSum == 0xECD99DC0) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pClrClssc.ROM");
- } else
- if (CheckSum == 0xECBBC41C) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pMacLCIII.ROM");
- } else
- if (CheckSum == 0xF1A6F343) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pQuad610.ROM");
- } else
- if (CheckSum == 0xF1ACAD13) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pQuad650.ROM");
- } else
- if (CheckSum == 0x5BF10FD1) {
- Length = (2 * 1024 * 1024UL);
- MyFileName = ((StringPtr)"\pQuad660.ROM");
- } else
- if (CheckSum == 0xFF7439EE) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pMacLC475.ROM");
- } else
- if (CheckSum == 0x0024D346)
- {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pDuo270.ROM");
- } else
- if ((CheckSum == 0xEDE66CBD)
- || (CheckSum == 0xEAF1678D))
- {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pMacLC550.ROM");
- } else
- if (CheckSum == 0x015621D7)
- {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pDuo280.ROM");
- } else
- if (CheckSum == 0xB6909089) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pPB520.ROM");
- } else
- if (CheckSum == 0x06684214) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pMacLC630.ROM");
- } else
- if (CheckSum == 0xFDA22562) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pPB150.ROM");
- } else
- if (CheckSum == 0x064DC91D) {
- Length = (1024 * 1024UL);
- MyFileName = ((StringPtr)"\pMacLC580.ROM");
- } else
- {
-
- #if 0
- /*
- this attempts to find the size of the ROM,
- but is it always safe? i.e. what if ROM
- doesn't repeat, reading from a random memory
- mapped device could have unpleasant
- results.
- */
- unsigned int L2Length;
- int i;
- unsigned long *p1;
- unsigned long *p2;
-
- L2Length = 16;
- Label_1:
- Length = 1 << L2Length;
- p1 = (unsigned long *)StartAddr;
- p2 = (unsigned long *)(StartAddr + Length);
- for (i = 256; --i >=0; ) {
- if (*p1++ != *p2++) {
- L2Length++;
- if (L2Length < 24) {
- goto Label_1;
- } else {
- /* can't find rom size */
- L2Length = 10;
- Length = 1 << L2Length;
- goto Label_2;
- }
- }
- }
- Label_2:
- #else
- /* so instead, just write out the checksum */
- Length = 4;
- #endif
- MyFileName = ((StringPtr)"\pUnknown.ROM");
- }
-
- /*
- use low level calls, since glue for higher level
- calls provided with my development environment do not
- work on Macintosh 128K
- */
-
- b.ioParam.ioCompletion = 0;
- b.ioParam.ioNamePtr = 0;
- if (0 == PBGetVol(&b, false)) {
-
- VRefNum = b.ioParam.ioVRefNum;
- b.ioParam.ioNamePtr = MyFileName;
- b.ioParam.ioVersNum = 0;
- err = PBCreate(&b, false);
- if (err == dupFNErr) {
- if (0 == PBDelete(&b, false)) {
- err = PBCreate(&b, false);
- }
- }
- if (0 == err) {
- b.ioParam.ioPermssn = fsRdWrPerm;
- b.ioParam.ioMisc = 0;
- if (0 == PBOpen(&b, false)) {
- b.ioParam.ioBuffer = (Ptr)(StartAddr);
- b.ioParam.ioReqCount = Length;
- b.ioParam.ioPosMode = fsFromStart;
- b.ioParam.ioPosOffset = 0;
- (void) PBWrite(&b, false);
- (void) PBClose(&b, false);
-
- b.fileParam.ioNamePtr = MyFileName;
- b.fileParam.ioVRefNum = VRefNum;
- b.fileParam.ioFVersNum = 0;
- b.fileParam.ioFDirIndex = 0;
- if (0 == PBGetFInfo(&b, false)) {
- b.fileParam.ioFlFndrInfo.fdType = MyFileType;
- b.fileParam.ioFlFndrInfo.fdCreator = MyCreator;
- (void) PBSetFInfo(&b, false);
- }
- }
- }
- }
- }
-